package com.liwq.base.thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @author : liwq
 * @version : 1.0
 * @date : 2023/1/10
 **/
public class ThreadTest {


    public static void main(String[] args) {
//        //用标准库中的线程池，创建出一个线程池中的实例
//        ExecutorService pool = Executors.newCachedThreadPool();
//        //给这个实例里面加入一些任务
//        for (int i = 0; i < 5; i++) {
//            pool.submit(new Runnable() {
//                @Override
//                public void run() {
//                    System.out.println("hello");
//                }
//            });
//        }


//        MyThread myThread = new MyThread();
//        myThread.start();


//        MyRunableImpl myRunable = new MyRunableImpl();
//        Thread thread = new Thread(myRunable);
//        thread.start();


        FutureTask<Integer> integerFutureTask = new FutureTask<>(new MyCallable());
        new Thread(integerFutureTask).start();



        try {
            Integer a = integerFutureTask.get();
            System.out.println("获取到了多线程的返回值：" + a);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }


        System.out.println("主线程结束");


    }
}
